import http from "@/http";

export const getUserList = (params?:any) => {
    return http({
        url:'/user/list',
        params,
        method:'get'
    }).then(res=>{
        return res.data
    })
}

export const create = (params?:any) => {
    return http({
        url:'/user/create',
        data: params,
        method:'post'
    })
}

export const update = (params?:any) => {
    return http({
        url:'/user/update',
        data: params,
        method:'post'
    })
}

export const uploadImg = (file) => {
    const formData = new FormData();
    formData.append('src', file);
    return http({
        url:'/api/upload.php',
        data: formData,
        method:'post'
    })
}

export const download = (params?:any) => {
    return http({
        url:'/api/user/download',
        responseType: "blob",
        params,
        method:'get'
    }).then(res => {
        const fileName = decodeURIComponent(res.headers?.["content-disposition"]?.split("filename* = ")?.[1]);
        const url = window.URL.createObjectURL(res.data);
        const a = document.createElement("a");
        a.href = url;
        a.download = fileName;
        a.click();

        window.URL.revokeObjectURL(url);
        a.remove();
    })
}